package cn.uce.cc.rest.control;

import cn.uce.base.entity.CcSmsRecord;
import cn.uce.cc.api.service.biz.ICcSmsMessageBiz;
import cn.uce.common.constants.CcConstants;
import cn.uce.common.omg.biz.IOmgOrgBiz;
import cn.uce.web.common.base.BaseController;
import cn.uce.web.common.base.CurrentUser;
import cn.uce.web.common.util.WebUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.*;


@Controller
@RequestMapping(value = "cc/SmsMessage")
public class CcSmsMessageController extends BaseController {
    private Logger log = LoggerFactory.getLogger(CcSmsMessageController.class);


    @Resource
    private ICcSmsMessageBiz ccSmsMessageBiz;

    @Resource
    private IOmgOrgBiz omgOrgBiz;

    /**
     * 弹屏首页发送短信 优速短信
     * @param sendPhone
     * @param sendContent
     * @return
     */
    @RequestMapping("/sendPhoneMessage")
    @ResponseBody
    public Map<String, Object> sendPhoneMessage(String sendPhone,String sendContent){
        CcSmsRecord ccSmsRecord = new CcSmsRecord();
        CurrentUser currentUser = WebUtil.getCurrentUser();
        ccSmsRecord.setCreateOrgCode(currentUser.getCmsBaseOrgCode());
        ccSmsRecord.setMoblileNum(sendPhone);
        ccSmsRecord.setContext(sendContent);
        ccSmsRecord.setPayOrgCode(omgOrgBiz.getHqOrgCode());
        ccSmsRecord.setCreateEmp(currentUser.getEmpName());
        ccSmsRecord.setTemplateCode(CcConstants.TEMPLATE_CUSTOM_CALL);
        ccSmsRecord.setProblemTypeName(CcConstants.TEMPLATE_CUSTOM_CALL);
        try {
            ccSmsMessageBiz.sendMessage(ccSmsRecord);
        } catch (Exception e) {
            log.error("CsSmsMessageController,sendPhoneMessage,Exception",e);
            returnError("发送短信失败");
        }
        return returnSuccess();
    }

    /**
     * 弹屏首页发送短信 壹米滴答短信模版
     * @param sendPhone
     * @param sendContent
     * @return
     */
    @RequestMapping("/ccosSendPhoneMessage")
    @ResponseBody
    public Map<String, Object> ccosSendPhoneMessage(String sendPhone,String sendContent){
        CcSmsRecord ccSmsRecord = new CcSmsRecord();
        CurrentUser currentUser = WebUtil.getCurrentUser();
        ccSmsRecord.setCreateOrgCode(currentUser.getCmsBaseOrgCode());
        ccSmsRecord.setMoblileNum(sendPhone);
        ccSmsRecord.setContext(sendContent);
        ccSmsRecord.setPayOrgCode(omgOrgBiz.getHqOrgCode());
        ccSmsRecord.setCreateEmp(currentUser.getEmpName());
        ccSmsRecord.setTemplateCode(CcConstants.CC_COMMON);
        ccSmsRecord.setProblemTypeName(CcConstants.CC_COMMON);
        try {
            ccSmsMessageBiz.sendMessage(ccSmsRecord);
        } catch (Exception e) {
            log.error("CsSmsMessageController,sendPhoneMessage,Exception",e);
            returnError("发送短信失败");
        }
        return returnSuccess();
    }
}
